.jenkins-form {
}

.jenkins-form-item {
  max-width: var(--form-item-max-width);
  margin-bottom: 1.75rem;

  // Workaround for float:right button controls
  // (eg Global Credentials' Verify Configuration button being hidden by the floating submit bar)
  &::after {
    content: " "; /* Older browser do not support empty content */
    visibility: hidden;
    display: block;
    height: 0;
    clear: both;
  }

  &--small {
    max-width: var(--form-item-max-width--small);
  }

  &--medium {
    max-width: var(--form-item-max-width--medium);
  }

  &--full-width {
    max-width: none;
  }
}

.jenkins-fieldset {
  border: none;
  margin: 0;
  padding: 0;

  .jenkins-form-item:last-of-type {
    margin-bottom: 0;
  }
}

.jenkins-form-label {
  display: flex;
  align-items: center;
  font-weight: var(--form-label-font-weight);
  margin-top: 0;
  margin-bottom: 0.75rem;
  padding-inline-start: 0;
  padding-inline-end: 0;
}

.jenkins-form-description {
  display: block;
  margin-top: 0;
  margin-bottom: 0.75rem;
  color: var(--text-color-secondary);
}

.jenkins-input {
  display: block;
  background: var(--input-color);
  border: 2px solid var(--input-border);
  padding: var(--form-input-padding);
  border-radius: var(--form-input-border-radius);
  width: 100%;
  box-shadow: var(--form-input-glow);
  transition: var(--standard-transition);

  &:hover {
    border-color: var(--input-border-hover);
  }

  &:active,
  &:focus {
    outline: none;
    border-color: var(--focus-input-border);
    box-shadow: var(--form-input-glow--focus);
  }
}

.jenkins-search {
  position: relative;
  max-width: 420px;

  &__input {
    appearance: none;
    display: block;
    background: var(--input-color);
    border: 2px solid var(--input-border);
    border-radius: var(--form-input-border-radius);
    width: 100%;
    margin: 0;
    padding: 0 4px 0 29px;
    line-height: 30px;
    box-shadow: var(--form-input-glow);
    transition: var(--standard-transition);

    // Safari adds unwanted padding - let's remove it
    &::-webkit-search-decoration {
      -webkit-appearance: none;
    }

    // By default the clear text button doesn't change the cursor on hover - lets turn it into a pointer
    &::-webkit-search-cancel-button:hover {
      cursor: pointer;
    }

    &:hover {
      border-color: var(--input-border-hover);
    }

    &:active,
    &:focus {
      outline: none;
      border-color: var(--focus-input-border);
      box-shadow: var(--form-input-glow--focus);
    }
  }

  &__icon {
    position: absolute;
    top: 9px;
    left: 9px;
    width: 16px;
    height: 16px;
    fill: var(--input-border-hover);
    transition: var(--standard-transition);
  }

  &::before {
    content: "";
    position: absolute;
    top: 17px;
    left: 17px;
    width: 0;
    height: 0;
    color: inherit;
    border: 2px solid currentColor;
    border-radius: 100%;
    opacity: 0;
    transition: var(--standard-transition);
  }

  &::after {
    content: "";
    position: absolute;
    top: 17px;
    left: 17px;
    width: 0;
    height: 0;
    color: inherit;
    border: 2px solid currentColor;
    border-radius: 100%;
    clip-path: inset(0 0 50% 50%);
    opacity: 0;
    transition: var(--standard-transition);
    animation: loading-spinner 1s infinite linear;

    @media (prefers-reduced-motion) {
      animation-duration: 2s;
    }
  }

  &--loading {
    .jenkins-search__icon {
      opacity: 0;
      transform: scale(0);
    }

    &::before {
      opacity: 0.2;
      top: 9px;
      left: 9px;
      width: 16px;
      height: 16px;
    }

    &::after {
      opacity: 1;
      top: 9px;
      left: 9px;
      width: 16px;
      height: 16px;
    }
  }

  &:focus-within {
    .jenkins-search__icon {
      fill: var(--focus-input-border);
    }
  }
}

@keyframes loading-spinner {
  to {
    transform: rotate(360deg);
  }
}

.jenkins-radio {
  margin-top: 2px;

  &:not(:last-of-type) {
    margin-bottom: 20px;
  }

  &__input {
    position: absolute;
    opacity: 0;
  }

  &__label {
    position: relative;
    display: inline-block;
    margin-bottom: 0;
    padding: 0 32px 5px;
    cursor: pointer;
    font-weight: 600;
    // remove 300ms pause on mobile
    touch-action: manipulation;

    &::before {
      content: "";
      box-sizing: border-box;
      position: absolute;
      top: 0;
      left: 0;

      width: 22px;
      height: 22px;

      border: 2px solid var(--input-border);
      border-radius: 50%;
      background: transparent;
      box-shadow: var(--form-input-glow);

      transition: var(--standard-transition);
    }

    &:hover::before {
      border-width: 5px;
      border-color: var(--input-border-hover);
    }
  }

  &__input:focus + &__label:before, &__input:active + &__label:before {
    border-width: 8px;
    border-color: var(--focus-input-border);
    box-shadow: var(--form-input-glow--focus);
  }

  &__input:checked + &__label:before {
    border-width: 8px;
    border-color: var(--focus-input-border);
  }

  &__description {
    margin: 0 0 0 32px;
    color: var(--text-color-secondary);
    line-height: 1.66;
  }

  &__children {
    position: relative;
    margin-top: 0;
    opacity: 0;
    padding-left: 32px;
    transition: var(--standard-transition);
    visibility: hidden;
    max-height: 0;

    &::after {
      content: "";
      position: absolute;
      top: 0;
      left: 10px;
      bottom: 0;
      width: 2px;
      background: var(--input-border);
      border-radius: 2px;
      transition: var(--standard-transition);
    }

    &:focus-within {
      &::after {
        background: var(--focus-input-border);
      }
    }
  }

  &__input:checked + &__label + &__children {
    visibility: visible;
    margin-top: 10px;
    opacity: 1;
    max-height: none;
  }
}

.jenkins-help-button {
  position: relative;
  width: 18px;
  height: 18px;
  min-width: 18px;
  min-height: 18px;
  margin-left: 1ch;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  color: var(--text-color)!important;
  line-height: 18px;
  border-radius: 100%;

  &::before {
    content: "?";
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: var(--text-color);
    opacity: 0.1;
    border-radius: inherit;
    transition: var(--standard-transition);
  }

  &::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    box-shadow: var(--form-input-glow);
    border-radius: inherit;
    opacity: 0.1;
    transition: var(--standard-transition);
  }

  &:hover {
    text-decoration: none;

    &::before {
      opacity: 0.2;
    }
  }

  &:active, &:focus {
    outline: none;
    text-decoration: none;

    &::before {
      opacity: 0.3;
    }

    &::after {
      box-shadow: 0 0 0 5px var(--text-color);
    }
  }
}

.jenkins-toggle-switch {
  position: relative;
  display: inline-block;
}

.jenkins-toggle-switch input {
  position: absolute;

  width: 1px;
  height: 1px;

  // If margin is set to a negative value it can cause text to be announced in
  // the wrong order in VoiceOver for OSX
  margin: 0;
  padding: 0;

  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);

  &:disabled {
    & + label {
      cursor: default;

      &::before {
        opacity: 0.25 !important;
        background-color: var(--input-border) !important;
        box-shadow: none !important;
      }

      &::after {
        opacity: 0.5 !important;
      }
    }
  }

  &:checked + label::before {
    background-color: var(--focus-input-border);
  }

  &:checked + label::after {
    left: 25px;
    color: var(--focus-input-border);
    transform: rotate(0deg);
  }

  &:active + label::before, &:focus + label::before {
    box-shadow: 0 0 0 5px var(--focus-input-glow);
  }
}

.jenkins-toggle-switch label {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  margin: 0;
  cursor: pointer;
  line-height: 30px;
  font-weight: bold;

  &::before {
    display: inline-block;
    content: "";
    position: relative;
    min-width: 50px;
    min-height: 30px;
    background: var(--input-border);
    border-radius: 19px;
    transition: 0.2s ease;
    margin-right: 15px;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05), 0 0 0 10px transparent;
  }

  &::after {
    content: "✓";
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 5px;
    left: 5px;
    width: 20px;
    height: 20px;
    background: var(--background);
    border-radius: 19px;
    color: transparent;
    transition: 0.2s ease;
    transform: rotate(-90deg);
    font-size: 12px;
    padding-top: 2px;
    box-shadow: -1px 0 0 rgba(0, 0, 0, 0.1);
  }

  &:hover::before {
    background-color: var(--input-border-hover);
  }

  &:active, &:focus {
    &::before {
      box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05), 0 0 0 5px var(--focus-input-glow);
    }
  }
}
